#! /usr/bin/python

description = """ This script will plot multiple pickled data returned from cli_lfp_weighed average"""

import sys
import cPickle

import pylab


from projects.electrophysiology.view_data import frame_utils
#-----------------------PARSE COMMAND LINE ARGS-------------

color_list = []
filename_list = []
frac_list = []
for arg in sys.argv[1:]:
    if '=' in arg:
        color, pickle_filename = arg.split('=')
        if ':' in color:
            color, frac = color.split(':')
            frac = float(frac)
            frac_list.append(frac)
        color_list.append(color)
        filename_list.append(pickle_filename)

if len(sys.argv) == 1:
    print description
    print "useage: <color>:<fraction>=<pickle_filename>"
    sys.exit(1)

#-----------------------READ IN PICKLES---------------------
result_list = []
for pickle_filename in filename_list:
    print "reading in the cpickle file %s" % pickle_filename
    with open(pickle_filename, 'r') as infile:
        result_list.append(cPickle.load(infile))

norm_image_list = []
for result, fraction in zip(result_list, frac_list):
    # get the image
    image = result['results']
    # normalize the image
    norm_image_list.append(frame_utils.saturating_linear_norm(image, fraction))

#color compose the image
pylab.figure()
pylab.title('Whatever title you want')
axes = pylab.subplot(111)
frame_utils.color_compose(norm_image_list, color_list, 
                          axes, bg='white', invert_alpha=True)
pylab.show()
